package com.siblings.loan.ui.permission

import android.graphics.Color
import android.view.LayoutInflater
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import com.lib.base.base.BaseFragment
import com.siblings.loan.databinding.PagePermissionBinding
import com.siblings.loan.ui.permission.adapter.SibPermissionAdapter
import org.json.JSONObject

/**
 * SiblingsLoan
 * @Author wwdeng
 * @CreateTime: 2024/7/5 15:03
 * @Annotation：权限Page
 */
class SibPermissionPage(val data: JSONObject): BaseFragment() {
    lateinit var binding: PagePermissionBinding

    //权限描述列表
    private var permissionAdapter: SibPermissionAdapter? = null

    override fun getSibRootView(inflater: LayoutInflater): View {
        binding = PagePermissionBinding.inflate(inflater)
        return binding.root
    }

    override fun initSibView() {
        rootViewBinding.containerLayout.setBackgroundColor(Color.parseColor("#00000000"))

        initSibRecyclerView()
    }

    override fun initSibListener() {
    }

    override fun initSibData() {
        val desArray = data.optJSONArray("msgList")
        val desList = arrayListOf<JSONObject>()
        if (desArray != null && desArray.length() > 0){
            for (i in 0..<desArray.length()){
                desList.add(desArray.optJSONObject(i))
            }
        }
        permissionAdapter!!.data = desList
    }

    /* 初始化列表 */
    private fun initSibRecyclerView(){
//        binding.rvPermission.visibility = View.GONE
//        binding.rvPermission.setHasFixedSize(true)
//        binding.rvPermission.isNestedScrollingEnabled = false
//        binding.rvPermission.isFocusableInTouchMode = false //不需要焦点
        val layoutManager = LinearLayoutManager(context)
        binding.recyclerView.layoutManager = layoutManager
        permissionAdapter = SibPermissionAdapter(binding.recyclerView)
        permissionAdapter!!.setOnItemChildClickListener { _, _, position ->
            val item = permissionAdapter!!.getItem(position)
        }
        binding.recyclerView.adapter = permissionAdapter
    }
}